home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / ums / ums-beta / rexx / mailforwarder.rexx < prev    next >
OS/2 REXX Batch file  |  1995-01-25  |  4KB  |  166 lines

  1. /*
  2. *$VER: UMS MailForwarder V1.1
  3. *
  4. *Forward mails width UMS. You *must* read mailforwarder.doc
  5. *to use this.
  6. *
  7. *Author:  Stefan Sticht, sticht@edith.deg.sub.org, 2:2494/22.4@fidonet
  8. *History: V1.0 03 Jan 94 Sticht   first version
  9. *History: V1.1 27 Jul 94 hG       · use UMSInit.rexx and hgrexxsupport.library
  10. *History:                         · template according LoginGuide
  11. *History:                         · copies msg no longer, just changes some fields
  12. *History: v1.2 25 Jan 95 hG       adapted to UMS V11
  13. *
  14. */
  15.  
  16. /*** Startup ***/
  17.  
  18. ReplyName = "Mail-Daemon"; ReplyPassword = "";
  19.  
  20. ProgramName = "MailForwarder";
  21. ArgsTemplate = "Name,Password,Server/K"
  22.  
  23. call addlib("hgrexxsupport.library",0,-30);
  24. interpret include("ums:s/UMSInit.rexx")
  25. if rc ~= 0 then do
  26.   say "cannot read UMS include-file!"
  27.   exit 20
  28. end
  29.  
  30. /*** Login ***/
  31.  
  32. /*
  33.  *  login as user
  34.  */
  35. account = UMSLogin(Name, Password, Server)
  36. IF account = 0 THEN DO
  37.     SAY "unable to login as user '" || Name || "'!"
  38.     EXIT
  39.     END
  40.  
  41. /*
  42.  *  login as importer "mailforwarder", too
  43.  */
  44. faccount = UMSLogin(ReplyName, ReplyPassword)
  45. IF faccount ~= 0 THEN DO
  46.  
  47.   Empty_Flags = MakeFlags()
  48.   FLAG_0 = MakeFlags(0)
  49.   FLAG_1 = MakeFlags(1)
  50.   FLAGS_01 = MakeFlags(0,1)
  51.   Mask =  MakeFlags(UMSUSTAT_ViewAccess, UMSUSTAT_Old)
  52.   Match = MakeFlags(UMSUSTAT_ViewAccess)
  53.  
  54.     /*
  55.      *  read our config vars for this user
  56.      */
  57.     toaddr = UMSReadConfig(account, "mailforwarder.toaddr", Name, 0)
  58.     toname = UMSReadConfig(account, "mailforwarder.toname", Name, 0)
  59.  
  60.     IF toname ~= "" THEN DO
  61.  
  62.         /*
  63.          *  select all new mails for this account
  64.          *
  65.          *  set local flag 0 on all new messages
  66.          */
  67.         CALL UMSSelectFlags(account, "L", FLAG_0, Empty_Flags,,, "U", Mask, Match)
  68.         /*
  69.          *  set local flag 1 on all mails
  70.          */
  71.         CALL UMSSelectField(account, "L", FLAG_1, Empty_Flags,,, UMSCODE_Group, "", TRUE)
  72.  
  73.         /*
  74.          *  main loop: read, convert and write all unread messages
  75.          */
  76.         last = 0
  77.         msgs = 0
  78.         DO FOREVER
  79.             /*
  80.              *  find next message with local flags 0 and 1 set
  81.              */
  82.             last = UMSSearchFlags(account, "LOCAL", FLAGS_01, FLAGS_01, last)
  83.             IF last = 0 THEN LEAVE
  84.             /*
  85.              *  read message
  86.              */
  87.             DROP msg.
  88.             IF UMSReadMsgAll(account, last, msg.) THEN DO
  89.                 IF UMSReadMsgInfo(account, last, msg.) THEN DO
  90.                     /*
  91.                      *  convert message
  92.                      */
  93.                     msg.UMSCODE_ToName = toname
  94.                     IF toaddr ~= "" THEN msg.UMSCODE_ToAddr = toaddr
  95.                     ELSE drop msg.UMSCODE_ToAddr
  96.  
  97.                     msg.hardlink = last
  98.  
  99.                     /*
  100.                      *  write message
  101.                      */
  102.                     IF UMSWriteMsg(faccount, msg.) = 0 THEN CALL CheckErr(faccount)
  103.                     ELSE msgs = msgs + 1
  104.                     END
  105.  
  106.                 ELSE CALL CheckErr(account)
  107.                 END
  108.  
  109.             ELSE CALL CheckErr(account)
  110.             END /* DO FOREVER */
  111.  
  112.         /*
  113.          *  display a short report
  114.          */
  115.         IF msgs > 0 THEN SAY "Forwarded" msgs "mail(s) to" toname || "."
  116.         ELSE SAY "Nothing to forward."
  117.         END
  118.  
  119.     ELSE DO
  120.         SAY "No mailforwarder installed for this user!"
  121.         END
  122.     END
  123. ELSE DO
  124.     SAY "Unable to login as user 'mailforwarder'!"
  125.     SAY "Check your configuration!"
  126.     END
  127.  
  128. /*** Final cleanup ***/
  129.  
  130. BREAK_C:
  131. BREAK_D:
  132. BREAK_E:
  133. BREAK_F:
  134. ERROR:
  135. HALT:
  136. IOERR:
  137. SYNTAX:
  138.  
  139. IF RC ~= 0 THEN DO
  140.     SAY "Error:" rc ERRORTEXT(rc) "in line" sigl
  141.     END
  142.  
  143. /*** Logout ***/
  144.  
  145. IF faccount ~= 0 THEN DO
  146.     CALL UMSLogout(faccount)
  147.     faccount = 0
  148.     END
  149.  
  150. IF account ~= 0 THEN DO
  151.     CALL UMSLogout(account)
  152.     account = 0
  153.     END
  154.  
  155. EXIT
  156.  
  157. /*** Support ***/
  158.  
  159. CheckErr: PROCEDURE
  160.     PARSE ARG account
  161.     err = UMSErrNum(account)
  162.     IF err ~= 0 THEN DO
  163.         SAY "UMS Error #" || err || ": " || UMSErrTxt(account)
  164.     END
  165.     RETURN
  166.